<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-08-08
 * Time: 15:29
 */

namespace App\Http\Controllers\Task;
use App\Http\Controllers\Controller;
use App\Model\Backstage\Customers;
use App\Model\Backstage\MoveRule;
use App\Model\Backstage\MoveRuleStatus;
use App\Model\Backstage\RoomInfo;
use App\Tool\Error;
use Illuminate\Support\Facades\DB;

/**
 * Class UpdateMoveRuleController
 * @package App\Http\Controllers\Task
 * 每天定时将公司是否更新规则改为否
 */
class UpdateMoveRuleController extends Controller
{
    public function updateStatus(){
//        $status = MoveRuleStatus::updateStatus();
        $MoveRuleStatus = new MoveRuleStatus();
        $status = $MoveRuleStatus->updateStatus();
        if($status){
            echo '更新成功';
        }else{
            echo Error::EDIT_ERROR;
        }
        exit();
    }


//////////////////////////////////////////////====================下面的方法不要动  有用====================//////////////////////////////////////////////////////////////////////////////////////////
    public function addData()
    {
        //获取部门ID
        $sidArr = [28,29,30,31,35];
        $sId =array_rand($sidArr);//部门ID
        $uid = array_rand(DB::table('user')->where('u_d_id', $sId)->value(DB::raw('GROUP_CONCAT(u_id) as u_id')));//员工ID

        $a = 100000;
        for($i=0; $i<$a; $i++) {
            DB::table('department')->insertGetId([
                'c_id'    => 1,
                'name'    => self::getHanzi(),
                'type'    => array_rand([1,2,3,4,5]),
                'address'    => self::getHanzi(),
                'to_work_time'    => '09:30',
                'after_work_time'    => '16:30',
                'd_superior_id'    => 28,
                'created_at'   => time(),
                'updated_at'   => time(),
            ]);
        }
        echo '执行完毕！';
    }


    //获取随机字符串
    public function getHanzi($giveStr="",$num=10)
    {
        $str = "哈森撒大葱撒出的主要产品是听见啦金玉良缘冰清玉洁继往开来锦绣山河冰雪聪明功成名就桃花潭水深千尺不及汪伦送我情先帝创业未半而中道今天下三分益州疲弊此诚危急存亡之秋也然侍卫之臣不懈于内忠志之士忘身于外者盖追先帝之殊遇欲报之于陛下也诚宜开张圣听";# 字库
        $newStr  = "";       # 随机生成的包含答案的字符串
        $anLo    = array();  # 设定的答案所在的位置。
        $bit     = 1;        # 位数，在本系统中是utf-8编码，一个中文长度为3
        $anLenth = floor(strlen($giveStr)/$bit); # 答案长度,在UTF编码中，

        # 这些汉字在18个汉字中的位置
        $i = 0;
        while ( $i<$anLenth ) {
            $rd = rand( 0, $num-1 );
            if(in_array($rd,$anLo)) continue; # 保证了不重复。
            $anLo[] = $rd;
            $i++;
        }

        for( $j=0; $j<$num;$j++ ){
            if(in_array($j,$anLo)){
                $k = array_search($j,$anLo);
                $newStr .= mb_substr($giveStr,$k*$bit,$bit); #echo $newStr."<br>";

            } else {
                $rd  = rand(0,(strlen($str)-1)/$bit);
                $wd  = mb_substr($str,$rd*$bit,$bit);
                $str = str_replace($wd, '', $str);
                $newStr .= $wd;
            }
        }
        return $newStr;
    }

}